package thread.demo01;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * 多个线程操作同一个对象
 */
public class Thread04 implements Runnable {

    // 票数
    private Integer tickNum = 10;


    @SneakyThrows
    @Override
    public void run() {
        while (true) {
            if (tickNum < 0) {
                break;
            }
            Thread.sleep(200);
            tickNum--;
            System.err.println(Thread.currentThread().getName()+"拿到了" + tickNum+ "张票");
        }
    }

    public static void main(String[] args) {
        Thread04 thread04 = new Thread04();
        new Thread(thread04,"小明").start();
        new Thread(thread04,"小张").start();
        new Thread(thread04,"小敦").start();
    }
}
